﻿Imports System
Imports ACompany.OrderProcessing.Presentation
Imports ACompany.OrderProcessing.Model
Imports System.Collections.Generic

Partial Class UserControls_Customer_CustomerEdit
    Inherits System.Web.UI.UserControl
    Implements ICustomerView


    Private _Presenter As CustomerPresenter

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        _Presenter = New CustomerPresenter(Me)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            _Presenter.Display()
        End If
    End Sub

    Public ReadOnly Property CustomerId() As Guid Implements ACompany.OrderProcessing.Presentation.ICustomerView.CustomerId
        Get
            Dim SelectedCustomerId As Guid
            If String.IsNullOrEmpty(Request.QueryString("CustomerId")) Then
                SelectedCustomerId = Guid.Empty
            Else
                SelectedCustomerId = New Guid(Request.QueryString("CustomerId"))
            End If

            Return SelectedCustomerId
        End Get
    End Property

    Protected Sub btnSaveCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveCustomer.Click
        _Presenter.SaveCustomer()
    End Sub

    Public Property City() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.City
        Get
            Return Me.txtCity.Text
        End Get
        Set(ByVal value As String)
            Me.txtCity.Text = value
        End Set
    End Property

    Public Property County() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.County
        Get
            Return Me.txtCounty.Text
        End Get
        Set(ByVal value As String)
            Me.txtCounty.Text = value
        End Set
    End Property

    Public Property Email() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.Email
        Get
            Return Me.txtEmail.Text
        End Get
        Set(ByVal value As String)
            Me.txtEmail.Text = value
        End Set
    End Property

    Public Property Name() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.Name
        Get
            Return Me.txtName.Text
        End Get
        Set(ByVal value As String)
            Me.txtName.Text = value
        End Set
    End Property

    Public Property PostCode() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.PostCode
        Get
            Return Me.txtPostCode.Text
        End Get
        Set(ByVal value As String)
            Me.txtPostCode.Text = value
        End Set
    End Property

    Public Property Street() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.Street
        Get
            Return Me.txtStreet.Text
        End Get
        Set(ByVal value As String)
            Me.txtStreet.Text = value
        End Set
    End Property

    Protected Sub btnCancelEditCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelEditCustomer.Click
        Response.Redirect("CustomerList.aspx")
    End Sub


    Public WriteOnly Property SaveButtonText() As String Implements ACompany.OrderProcessing.Presentation.ICustomerView.SaveButtonText
        Set(ByVal value As String)
            Me.btnSaveCustomer.Text = value
        End Set
    End Property

    Public Sub ErrorMessage(ByVal Message As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.ErrorMessage
        If String.IsNullOrEmpty(Message) Then
            pnlError.Visible = False
        Else
            pnlError.Visible = True
        End If
        Me.litErrorMessage.Text = Replace(Message, Environment.NewLine, "<br/>")
    End Sub

    Public Sub InfoMessage(ByVal Message As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.InfoMessage
        If String.IsNullOrEmpty(Message) Then
            pnlInfo.Visible = False
        Else
            pnlInfo.Visible = True
        End If
        Me.litInfoMessage.Text = Replace(Message, Environment.NewLine, "<br/>")
    End Sub

    Public Sub ViewTitle(ByVal title As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.ViewTitle
        Me.litTitle.Text = title
    End Sub
End Class
